listbox: Scroll headers on screen
authorMatthias Clasen <mclasen@redhat.com>
Sun, 13 Jul 2014 16:31:28 +0000 (12:31 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 13 Jul 2014 17:00:37 +0000 (13:00 -0400)
The listbox code relies on the container focus adjustment handling
to scroll the cursor row on screen. But GtkContainer has no idea
about row headers, so ensure that we scroll the header on screen too.

gtk/gtklistbox.c

index 2958a3ad23bfd3c59f90cb738abc171408f2824c..d3afac46b5d355f01545dcac5dba63561b74b4bc 100644 (file)
@@ -1326,11 +1326,32 @@ gtk_list_box_add_move_binding (GtkBindingSet   *binding_set,
                                 NULL);
 }
 
+static void
+ensure_row_visible (GtkListBox    *box,
+                    GtkListBoxRow *row)
+{
+  GtkListBoxPrivate *priv = BOX_PRIV (box);
+  GtkWidget *header;
+  GtkWidget *widget;
+  GtkAllocation allocation;
+
+  /* If the row has a header, we want to ensure that it is visible as well. */
+  header = ROW_PRIV (row)->header;
+  if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header))
+    widget = header;
+  else
+    widget = GTK_WIDGET (row);
+
+  gtk_widget_get_allocation (widget, &allocation);
+  gtk_adjustment_clamp_page (priv->adjustment, allocation.y, allocation.y + allocation.height);
+}
+
 static void
 gtk_list_box_update_cursor (GtkListBox    *box,
                             GtkListBoxRow *row)
 {
   BOX_PRIV (box)->cursor_row = row;
+  ensure_row_visible (box, row); 
   gtk_widget_grab_focus (GTK_WIDGET (row));
   gtk_widget_queue_draw (GTK_WIDGET (row));
   _gtk_list_box_accessible_update_cursor (box, row);
@@ -2682,7 +2703,8 @@ gtk_list_box_move_cursor (GtkListBox      *box,
     case GTK_MOVEMENT_DISPLAY_LINES:
       if (priv->cursor_row != NULL)
         {
-          int i = count;
+          gint i = count;
+
           iter = ROW_PRIV (priv->cursor_row)->iter;
 
           while (i < 0  && iter != NULL)